// pages/review/changeVocabulary/changeVocabulary.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        vocabularyImgs :["schools","high_school","cet4","cet6","pu"], 
        constant:[2113,2163,2029,1041,3519],
        books:[
            {
                id:0,
                name: "中小学词汇",
                num:0,
                total:2113
            },
            {
                id:1,
                name: "高中词汇",
                num:0,
                total:2163
            },
            {
                id:2,
                name: "四级词汇",
                num:0,
                total:2029
            },
            {
                id:3,
                name: "六级词汇",
                num:0,
                total:1041
            },
            {
                id:4,
                name: "考研词汇",
                num:0,
                total:3519
            },
        ],
        learnVocabulary:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        var app = getApp();
        wx.request({
          url: 'http://39.101.199.5:8888/SuJiWords/MemoriesNumber/getMemoriesNumber/'+app.globalData.loginPhoneNumber,
          method:"GET",
          success:res=>{
            var data = res.data.data   
            this.setData({
                books:[
                    {
                        id:0,
                        name: "中小学词汇",
                        num:data.schoolNum,
                        total:2113
                    },
                    {
                        id:1,
                        name: "高中词汇",
                        num:data.highSchoolNum,
                        total:2163
                    },
                    {
                        id:2,
                        name: "四级词汇",
                        num:data.cet4Num,
                        total:2029
                    },
                    {
                        id:3,
                        name: "六级词汇",
                        num:data.cet6Num,
                        total:1041
                    },
                    {
                        id:4,
                        name: "考研词汇",
                        num:data.postgraduataWordNum,
                        total:3519
                    },
                ]
            })
            this.getLearn_vocabulary();
          }
        })
        
    },
    getLearn_vocabulary(){
        var app = getApp()
        wx.request({
            url: 'http://39.101.199.5:8888/SuJiWords/user/getLearn_vocabulary/'+app.globalData.loginPhoneNumber,
            method:"GET",
            success:res=>{
                this.setData({
                    learnVocabulary : res.data.data
                 })
                }
        })
    },

    changeRequest(e){
        var app = getApp();
        wx.request({
          url: 'http://39.101.199.5:8888/SuJiWords/user/updateLearn_vocabulary',
          method:"POST",
          header:{
            'content-tupe':'application/json/charser=UTF-8'
            },
          data:{
            "phoneNumber":app.globalData.loginPhoneNumber,
            "vocabularyType":e.currentTarget.dataset.id
          },
          success:res=>{
              console.log(res)
              this.getLearn_vocabulary()
          }
        })
    
    }
})